#include "SypEngine.h"

#ifdef CHECKMEM
#include "mmgr.h"
#endif
//Define namespace
namespace Syp
{

Resource::Resource(const String& filename):ref(0),loaded(false), fileName(filename)
{
	ResourceManager::getResourceManager().addResource(this);	
}

Resource::~Resource()
{

}

void Resource::addInstance()
{
	++ref;
}

void Resource::removeInstance()
{
    --ref;
	/*if( ref==0 )
	{
		ResourceManager::getResourceManager().removeEntry( this->getFileName() );
	}*/
}

Resource::Resource(const Resource& r)
{
	if(this == &r)
	{
		ErrorLogger::getLogger()<<"Warning : Encountered Self-Assignment in Resource"<<std::endl;
		return;
	}
	fileName = r.fileName;	
}

void Resource::dumpResourceInfo()
{
	ErrorLogger::getLogger()<<"Resource filename: "<<fileName<<std::endl;		
	ErrorLogger::getLogger()<<"Resource ref: "<<getNumInstances()<<std::endl;	    
}

Resource& Resource::operator =(const Resource& m)
{
	//Handle self assignment
	if(this == &m)
	{
		ErrorLogger::getLogger()<<"Warning : Encountered Self-Assignment in Resource"<<std::endl;
		return *this;
	}
	fileName = m.fileName;
	return *this;
}
}
